// Mmanagement/adseeInfitem/adseeInfitem.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    c1lists:[],
    c2lists:[],
    c3lists:[],
    files:[],
    images:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    var shopnumber=options.shopnumber;
    that.setData({
      shopnumber
    })
    
    // 通过关联id分别请求三次请求
    // 店铺基本信息
    app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php', {num:4,shopnumber}).then(res=>{
      that.setData({
        c1lists:res
      })
    })
    // 店主信息
    app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php', {num:5,shopnumber}).then(res=>{
      that.setData({
        c2lists:res
      })
    })
    // 店员信息
    app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php', {num:6,shopnumber}).then(res=>{
      that.setData({
        c3lists:res
      })
    })
    // file文件信息表单
    app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php', {num:16,shopnumber,filetype:'file'}).then(res=>{
      that.setData({
        files:res
      })
    })
    // image信息表单
    app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php', {num:16,shopnumber,filetype:'image'}).then(res=>{
      that.setData({
        images:res
      })
    })
  },
  pdfclick(e){
    var pdfurl=e.target.dataset.pdfurl;
    wx.downloadFile({
      url: pdfurl,   
      success: function (res) {                           
        if (res.statusCode === 200) { 
          var Path = res.tempFilePath;
          wx.openDocument({
            fileType: 'pdf', 
            filePath: Path,         
            success: function (res) {
              console.log('打开 PDF 成功');
            }
          })
        }
      },
      fail: function (res) {
        console.log(res);  
      }
    })
  },
  imgclick(e){
    var imgsrc=e.target.dataset.src;
    wx.getImageInfo({
      src: imgsrc,
      success:res=>{
        var path=res.path;
        wx.saveImageToPhotosAlbum({
          filePath: path,
          success: res => {
            wx.showToast({
              title: '保存成功',
              icon: "success"
            })
          },
          fail: res => {
            wx.openSetting({
              success: settingdata => {
                if (settingdata.authSetting['scope.writePhotosAlbum']) {
                  console.log('获取权限成功，给出再次点击图片保存到相册的提示。')
                } else {
                  console.log('获取权限失败，给出不给权限就无法正常使用的提示')
                }
                console.log(settingdata)
              },
              fail: error => {
                console.log(error)
              }
            })
            wx.showModal({
              title: '提示',
              content: '保存失败，请确保相册权限已打开',
            })
          }
        })
      }
    })
    
  }
})